//
//  DeliveryTrackCell.m
//  ProjectforHDX
//
//  Created by motom on 16/8/11.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "DeliveryTrackCell.h"
#import "DeliverTrackingModel.h"
@interface DeliveryTrackCell()

@property (nonatomic, strong) DeliverModel *deliveryModel;

@end

@implementation DeliveryTrackCell

- (void)awakeFromNib {
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupView];
    }
    return  self;
}

#define CELL_Height 73
-(void)setDeliverModel:(DeliverModel *)model
{
    CGFloat pointBottom = 0;
    CGFloat linex = 21;
    CGFloat bottom = 0;
    CGFloat height = 37;
   
    
    for (int i =0; i<model.tracking.count; i++) {
        NSObject *obj = model.tracking[model.tracking.count -1- i];
        DeliverTrackingModel *modelTrack = (DeliverTrackingModel *)obj;
        UIView *view = [[UIView alloc]init];
        
//        [view setFrame:CGRectMake(0, 37+i*73, SCREEN_HEIGHT, CELL_Height)];
        
        [self addSubview:view];
        UIImage *image = nil;
        
        if (i==0) {
            image = BDFILEIMAGENAEM(@"Order/img_curDetail");
            UIImageView *imageV = [[UIImageView alloc]initWithImage:image];
            imageV.top = 15;
            imageV.left = 15;
            pointBottom = imageV.bottom;
            [view addSubview:imageV];
            
            //物流step
            RZCustomLable *deliverHistory = [[RZCustomLable alloc]init];
            deliverHistory.font = CustomFont(13);
            deliverHistory.attributedText = [[NSAttributedString alloc]initWithString:modelTrack.content attributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}];
            [view addSubview:deliverHistory];
            
            NSString *str = [NSString stringWithFormat:@"%@",deliverHistory.attributedText];
            CGSize size = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - imageV.right -20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:nil context:nil].size;
            [deliverHistory setFrame:CGRectMake(0, 0, size.width, size.height)];
            
            deliverHistory.top = 15;
            deliverHistory.left =imageV.right +20;
            deliverHistory.numberOfLines = 0;
            deliverHistory.font = CustomFont(13);
            [deliverHistory setTextColor:[UtilCheck hexStringToColor:@"23ae5d" alpha:1.0]];
            [deliverHistory sizeToFit];
            
            RZCustomLable *date = [[RZCustomLable alloc]init];
            NSLog(@"time  %@",modelTrack.time);
            date.text = modelTrack.time;
            date.top = deliverHistory.bottom +2;
            date.left = deliverHistory.left;
            [date sizeToFit];
            date.font = CustomFont(12);
            [date setTextColor:[UtilCheck hexStringToColor:@"23ae5d" alpha:1.0]];
            [view addSubview:date];
            
            bottom = date.bottom +10;

            
        }
        
        else
        {
            image =BDFILEIMAGENAEM(@"Order/img_historyDetail");
            UIImageView *imageV = [[UIImageView alloc]initWithImage:image];
        
            imageV.top = 15;
            imageV.left = 17;
            [view addSubview:imageV];
            
            //物流step
            RZCustomLable *deliverHistory = [[RZCustomLable alloc]init];
            deliverHistory.font = CustomFont(13);
            deliverHistory.attributedText = [[NSAttributedString alloc]initWithString:modelTrack.content attributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}];
            [view addSubview:deliverHistory];
            
            NSString *str = [NSString stringWithFormat:@"%@",deliverHistory.attributedText];
            CGSize size = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - imageV.right -20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:nil context:nil].size;
            [deliverHistory setFrame:CGRectMake(0, 0, size.width, size.height)];
            
            deliverHistory.top = 15;
            deliverHistory.left =imageV.right +20;
//            deliverHistory.lineBreakMode = UILineBreakModeWordWrap;
            deliverHistory.numberOfLines = 0;
            deliverHistory.font = CustomFont(13);
            [deliverHistory setTextColor:[UtilCheck hexStringToColor:@"868686" alpha:1.0]];
            [deliverHistory sizeToFit];

            //日期
            RZCustomLable *date = [[RZCustomLable alloc]init];
            [date setTextColor:[UIColor grayColor]];
            date.text = modelTrack.time;
            date.top = deliverHistory.bottom +2;
            date.left = deliverHistory.left;
            [date setTextColor:[UtilCheck hexStringToColor:@"868686" alpha:1.0]];
            date.font = CustomFont(12);
            [date sizeToFit];
            [view addSubview:date];
            
            bottom = date.bottom + 10;
        }
        [view setFrame:CGRectMake(0, height, SCREEN_WIDTH, bottom)];
        height  = height + bottom;
        
        
        [view addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"f0f0f0" alpha:1] pointA:CGPointMake(40, view.height) pointB:CGPointMake(view.width, view.height)];
    }
    self.backgroundColor = [UIColor whiteColor];
    self.cellHeight = height;
      //贯穿线
     [self addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"cccccc" alpha:1] pointA:CGPointMake(linex, pointBottom+37) pointB:CGPointMake(linex, height)];
  
    [self addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"#f0f0f0" alpha:1] pointA:CGPointMake(0, height) pointB:CGPointMake(SCREEN_WIDTH, height)];
}

-(void)setupView
{
    self.backgroundColor = [UIColor whiteColor];
    
    //线
    [self addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"f0f0f0" alpha:1] pointA:CGPointMake(0, 0) pointB:CGPointMake(SCREEN_WIDTH, 0)];
    
    //物流跟踪
    RZCustomLable *label = [[RZCustomLable alloc]init];
    label.text = [THMangerTool language:@"customer.logTrack"];
    label.font = CustomFont(14);
    [label setTextColor:[UtilCheck hexStringToColor:@"171717" alpha:1.0]];
    label.top = 10;
    label.left = 10;
    [label sizeToFit];
    [self addSubview:label];
    
    //线
    [self addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"f0f0f0" alpha:1] pointA:CGPointMake(10, label.bottom+10) pointB:CGPointMake(SCREEN_WIDTH-10, label.bottom+10)];
    //顶部i
    [self addSoldLine:1.0 soldcolor:[UtilCheck hexStringToColor:@"f0f0f0" alpha:1.0] pointA:CGPointMake(0,0) pointB:CGPointMake(SCREEN_WIDTH, 0)];


}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
